package br.com.dren.site.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;

@WebServlet("/contact-us")
public class ContactUsController extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public ContactUsController() {
		super();
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String name = request.getParameter("name");
		String phone = request.getParameter("phone");
		String emailClient = request. getParameter("email");
		String subject = request.getParameter("subject");
		String message = request.getParameter("message");
		try {
			SimpleEmail email = new SimpleEmail();
			email.setHostName("smtp.gmail.com"); // o servidor SMTP para envio do e-mail
			email.setSmtpPort(465);
			email.setSSL(true);
			email.setAuthentication("", "");
			email.addTo("caaiotrindade@gmail.com", "Caio Trindade"); //destinatário
			email.setFrom(emailClient, name); // remetente
			email.setSubject(subject); // assunto do e-mail
			email.setMsg(message + "\n" + phone); //conteudo do e-mail
			email.send(); //envia o e-mail
		} catch(EmailException e) {
			e.printStackTrace();
		}
		

	}
}
